package com.sky.task;

import com.sky.mapper.OrderMapper;
import com.sky.mapper.UserMapper;
import com.sky.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @Author xushupeng
 * @Date 2025-01-04 10:41
 */
@Slf4j
@Component
public class OrderTask {

    @Autowired
    private OrderMapper orderMapper;

    private static Long startId=1L;
/**
 * 订单超时未支付
 */
//每分钟执行一次
@Scheduled(cron = "0 * * * * ?")
public void orderTimeOutCancelTask() {
    log.info("订单定时任务启动");
    //1 .检查订单是否 超时15min  并且支付状态为未支付  查询遍历所有订单 修改状态 update  set ...where ? and ?

    // 获取当前时间
    LocalDateTime currentTime = LocalDateTime.now();
    System.out.println("当前时间: " + currentTime);

    // 获取前 15 分钟的时间
    LocalDateTime timeBefore15Minutes = currentTime.minusMinutes(15);
    System.out.println("15 分钟前的时间: " + timeBefore15Minutes);
    //更新查询起始订单id
    String cancelReason="订单超时未支付";

    long count=orderMapper.updatePaymentTimeOutOrders(startId,cancelReason,timeBefore15Minutes);

     log.info("订单定时任务结束:"+"  更新了"+count+"条数据");
}



}
